package org.example.aaaatest.ctry;

import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Getter
public enum Country {

    KOREA("韩国", "410"),
    MALAYSIA("马来西亚", "458"),
    JAPAN("日本", "392"),
    THAILAND("泰国", "764"),
    INDONESIA("印度尼西亚", "360"),
    VIETNAM("越南", "704");

    private final String name;
    private final String adcode;

    Country(String name, String adcode) {
        this.name = name;
        this.adcode = adcode;
    }

    private static final Map<String, Country> AD_CODE_MAP;

    static {
        Map<String, Country> tempMap = new HashMap<>();
        for (Country country : values()) {
            tempMap.put(country.adcode, country);
        }
        AD_CODE_MAP = Collections.unmodifiableMap(tempMap);
    }

    public static Country findByAdcode(String adcode) {
        if (adcode == null) {
            throw new IllegalArgumentException("adcode cannot be null");
        }
        return AD_CODE_MAP.get(adcode);
    }
}
